import dialogBg from './../../assets/common/dialog/dialog_bg.png'
import { merge } from 'lodash'
/**
 * 获取url链接里面传过来的值
 * @param {String} name  获取值的名称
 * @return {String} 圆形轨迹坐标
 */
export function getUrlVal (name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [undefined, ''])[1].replace(/\+/g, '%20')) || null
}
/**
 * 货币转换
 * @param {String, Number} number  要格式化的数字
 * @param {Number} decimal  保留几位小数
 * @param {String} currency  货币符号
 * @param {String} thousands  千分位符号
 * @param {String} unit  货币单位
 */
export const numberFormat = (number, { decimal = 2, thousands = ',', currency = '￥', unit = '元' } = {}) => {
  const flag = isNaN(number)
  let v = Number(flag ? 0 : number).toFixed(decimal)
  flag && console.error(`The number(${number}) parameter cannot be converted to a number`)
  v = v.split('.')
  v[0] = v[0].replace(/\d{1,3}(?=(\d{3})+$)/g, `$&${thousands}`)
  v = [v.join('.')]
  v.unshift(currency)
  v.push(unit)
  return v.join('')
}
/**
 * 清理数据对象
 * @param {Object} d // 要清理的数据
 * @param {Array} el // 要排除的key
 * @param {Function} callback // 除了需要排除的数据，自定义清理方法
 * @returns Object
 */
export function clearParams (d, el = [], callback) {
  let excludeKeys = []
  excludeKeys = excludeKeys.concat(el)
  const resultData = JSON.parse(JSON.stringify(d, (k, v) => {
    if (excludeKeys.indexOf(k) !== -1) {
      v = undefined
    } else {
      v = !v && v !== 0 && typeof v !== 'boolean' ? undefined : !v.toString() ? undefined : v.toString() === '[object Object]' && Object.keys(v).length === 0 ? undefined : v
      if (v !== undefined && callback && typeof callback === 'function') {
        v = callback(k, v)
      }
    }
    return v
  }))
  return resultData
}
export function clearQueryParams (d, el = [], callback) {
  let excludeKeys = ['total', 'loading']
  excludeKeys = excludeKeys.concat(el)
  return clearParams(d, excludeKeys, callback)
}


export const dialogCustomStyle = (d) => {
  return merge({
    backgroundImage: `url(${dialogBg})`,
    backgroundPosition: '0 0',
    backgroundRepeat: 'no-repeat',
    backgroundSize: '212px 208px',
    borderRadius: '18px'
  }, d)
}